﻿@using System.Collections.Generic
@using System.Linq
@using MrCMS.Entities.Documents.Media
@using MrCMS.Paging
@using MrCMS.Helpers
@using MrCMS.Settings
@using MrCMS.Website
@model MrCMS.Web.Areas.Admin.Models.MediaSelectorSearchQuery
@{
    Layout = "~/Areas/Admin/Views/Shared/_LayoutPopup.cshtml";
    var categories = ViewData["categories"] as List<SelectListItem> ?? new List<SelectListItem>();
    var results = ViewData["results"] as IPagedList<MediaFile> ?? PagedList<MediaFile>.Empty;
    var mediaSettings = MrCMSApplication.Get<MediaSettings>();
}
<div data-type="media-selector-popup" style="min-height: 450px;">
    @using (Html.BeginForm("Show", "MediaSelector", FormMethod.Get, new { id = "search-form", @class = "form-inline" }))
    {
        <fieldset>
            <legend>
                @Resource("Admin Media Selector Media Selector Title", "Media Selector")
            </legend>
            <div class="form-container">
                <div class="form-group folder-dropdown">
                    @Html.DropDownListFor(query => query.CategoryId, categories, new { @class = "form-control col-sm-6" })
                    @Html.ValidationMessageFor(query => query.CategoryId)
                </div>
                <div class="form-group search-text">
                    @Html.TextBoxFor(query => query.Query, new { @class = "form-control col-xs-4", @placeholder = Resource("Admin - Media Selector Search Placeholder", "Search") })
                    @Html.ValidationMessageFor(query => query.Query)
                </div>
                <input type="submit" class="btn btn-primary col-lg-12 search-btn" value="@Resource("Search")" />
            </div>
        </fieldset>
    }

    <div id="results">
        <div id="fileupload" data-message="@Resource("Click here or drag files to upload")" class="dropzone margin-bottom-10 margin-top-10"></div>

        <input type="hidden" value="@Url.Action("Files", "File", new { Id = (Model.CategoryId ?? null) })" id="action-url" />


        <div id="progress" class="progress" style="height: 30px; display: none; margin-bottom: 5px;">
            <div class="bar"><span id="percent-complete" style="text-align: center;"></span></div>
        </div>
        <div id="files" class=""></div>


        <input type="hidden" id="allowedFileTypes" value="@FileTypeUploadSettings.AllowedFileTypes" />
        <input type="hidden" id="maxFileSizeUpload" value="@mediaSettings.MaxFileSizeUpload" />

        @if (results.Any())
        {
            foreach (var file in results)
            {
                Html.RenderPartial("FileResult", file);
            }
            <div class="clearfix"></div>
            @Html.Pager(results, "Show", page => new { page })
        }
        else
        {
            <p>
                @Html.InfoBlock("", Resource("Admin Media No Files Message", "There are no files here yet - why not upload some?"))
            </p>
        }
    </div>
</div>